//
//  TJActivationCodeCell.m
//  BaoDian
//
//  Created by mac on 2024/7/30.
//

#import "TJActivationCodeCell.h"
#import "TJButton.h"

@interface TJActivationCodeCell()

@property (nonatomic, weak) UILabel *activationCodeLabel;
@property (nonatomic, weak) UILabel *typeValueLabel;
@property (nonatomic, weak) UILabel *specificationLabelValueLabel;


@end

@implementation TJActivationCodeCell

 
- (void)settingSubView {
    [super settingSubView];
    

    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = UIColor.tj_backgroundColor;
    
    UIView *tj_contentView = [UIView addToView:self.contentView];
    tj_contentView.backgroundColor = UIColor.tj_1E1F23Color;
    tj_contentView.addCornerRadius(12);
    [tj_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.inset(16);
        make.top.offset(0);
    }];
    
    UIView *topView = [UIView addToView:tj_contentView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(0);
        make.top.offset(0);
        make.height.offset(54);
    }];
    
    UILabel *activationCodeLabel = [UILabel lableWithSuperView:topView font:UIFontSemiboldMake(24) color:UIColor.whiteColor title:nil textAlignment:NSTextAlignmentLeft];
    [activationCodeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.left.offset(16);
    }];
    
    TJButton *copyButton = [TJButton buttonWithSuperView:topView font:UIFontMake(14) color:UIColorMake(0x2978F0) title:@"复制"];
    [copyButton addTarget:self action:@selector(didClickCopyButton) forControlEvents:UIControlEventTouchUpInside];
    [copyButton sizeToFit];
    [copyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.inset(0);
        make.centerY.offset(0);
        make.width.offset(copyButton.tj_width + 32);
        make.height.offset(20);
    }];
    
    [topView addLineViewWithColor:UIColorMake(0x2D2D2D) block:^(MASConstraintMaker *make) {
        make.left.right.inset(16);
        make.bottom.offset(0);
        make.height.offset(1);
    }];
    
    UILabel *typeLabel = [UILabel lableWithSuperView:tj_contentView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:@"激活码类型" textAlignment:NSTextAlignmentLeft];
    [typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topView.mas_bottom).offset(12);
        make.left.equalTo(activationCodeLabel);
    }];
    
    UILabel *typeValueLabel = [UILabel lableWithSuperView:tj_contentView font:UIFontMake(14) color:UIColor.whiteColor title:@"员工分组激活码" textAlignment:NSTextAlignmentLeft];
    [typeValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(typeLabel.mas_right).offset(24);
        make.centerY.equalTo(typeLabel);
    }];
    
    UILabel *specificationLabel = [UILabel lableWithSuperView:tj_contentView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:@"激活码规格" textAlignment:NSTextAlignmentLeft];
    [specificationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(typeLabel.mas_bottom).offset(10);
        make.left.equalTo(activationCodeLabel);
    }];
    
    UILabel *specificationLabelValueLabel = [UILabel lableWithSuperView:tj_contentView font:UIFontMake(14) color:UIColor.whiteColor title:nil textAlignment:NSTextAlignmentLeft];
    [specificationLabelValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(specificationLabel.mas_right).offset(24);
        make.centerY.equalTo(specificationLabel);
    }];
    
    UIView *bottomView = [UIView addToView:tj_contentView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(0);
        make.top.equalTo(specificationLabel.mas_bottom).offset(12);
        make.bottom.offset(0);
    }];
    
    [bottomView addLineViewWithColor:UIColorMake(0x2D2D2D) block:^(MASConstraintMaker *make) {
        make.left.right.inset(16);
        make.top.offset(0);
        make.height.offset(1);
    }];
    
    UIButton *useButton = [UIButton buttonWithSuperView:bottomView font:UIFontMake(12) color:UIColor.whiteColor title:@"使用"];
    useButton.backgroundColor = UIColorMake(0x2978F0);
    useButton.addCornerRadius(14);
    [useButton addTarget:self action:@selector(didClickUseButton) forControlEvents:UIControlEventTouchUpInside];
    [useButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.right.inset(16);
        make.width.offset(48);
        make.height.offset(28);
    }];
    
    _activationCodeLabel = activationCodeLabel;
    _typeValueLabel = typeValueLabel;
    _specificationLabelValueLabel = specificationLabelValueLabel;
}


- (void)setModel:(TJActiveCodeModel *)model {
    _model = model;
    
    _activationCodeLabel.text = model.activationCode;
    _specificationLabelValueLabel.text = [NSString stringWithFormat:@"%@天，%@人", model.validDays, model.times];
}

- (void)didClickUseButton {
    if (_didClickUseButtonBlock) {
        _didClickUseButtonBlock();
    }
}

- (void)didClickCopyButton {
    [TJTools copyStringToPasteboard:self.model.activationCode];
    [TJHUD showMessage:@"复制成功"];
}

@end
